<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="keywords" content="">
	<meta name="description" content="">
	<!-- <link rel="shortcut icon" type="image/ico" href="/favicon.ico"> -->
	<title>${keyword}-搜索结果</title>
	<link rel="stylesheet" href="/css/imhere.css">
	<script type="text/javascript" src="/js/jquery-1.12.1.min.js"></script>
	<script type="text/javascript" src="/js/imhere.js"></script>
</head>
<body>
<div id="container">
	<div class="tool-bar">
		<!--提交表单-->
		<form id="kwform" action="/index" method="post">
			<div class="small-logo">
				<img src="/img/logo3.png" alt="" title=""/>
			</div>
			<div style="height: 54px; float: left;">
				<div style="position: relative;margin: 10px 0;">
					<input id="keyword" name="keyword" type="text" autocomplete="off" placeholder="请输入关键字"/>
					<ul id="keywordSug" style="top: 34px;"></ul>
				</div>
			</div>
			<div style="height: 54px; float: left;">
				<button id="searchBtn" class="search-btn" type="button">网盘一下</button>
			</div>
		</form>
		<!--提交表单-->
		<div class="link-entrance">
			<a href="http://blog.here325.com" target="_blank">大雄博客</a>&nbsp;&nbsp;
		</div>
	</div>

	<div class="nav-bar">
		<div>
			<div class="nav-item">
				搜索结果
			</div>
		</div>
	</div>



		<div style="clear: both;"></div>
	</div>

</div>
</body>

<script type="text/javascript">
	$(function(){//加载页面时载入函数
		$("#keyword").focus().val('${keyword}');	//输入框聚焦
		$("#searchBtn").click(function(){
			getPageData(1);
		});

		$("#searchBtn").click();
		//键盘事件
		$(window).keydown(function(e){
			var keyCode = e.which || e.keyCode;
			if(keyCode==116) {	//刷新按钮F5
				$("#kwform").submit();//跳回到表单界面
				e.preventDefault();
				return;
			}
		});

		$("#switchPic span").click(function(){
			var isActive = $(this).hasClass("active");
			if(isActive) return;
			$("#switchPic span").removeClass("active");
			$(this).addClass("active");
			$(".donate-inner img").hide();
			var domId = $(this).attr("id");
			$(".donate-inner ." + domId).show();
		});
	});

	function getPageData(page) {
		//取到框里的值
		var keyword = $("#keyword").val();
		//展示css样式
		$("#loading").show();

		page = page || 1;
		//简写的ajax
//		$.ajax({
//			type:"",
//			utl:"",
//			datatype:"",
//			success:
//			data:
//			error:
//		});
		$.post("/ajaxSearch", {keyword: keyword, page: page, type: "pc"}, function(data){
			$("#loading").hide();
			if(data.status == 1) {
				var dataMap = data.data;
				var result = dataMap.items;
				if(result.length < 1) {
					$("#resultList").html("<div class='search-tips'>搜不到您要的资料，换个更优雅的姿势搜吧~~:-D</div>");
					return;
				}
				var html = "";

				for(var i=0; i<result.length; i++) {
					html += '<div class="data-item">'+
							'	<a class="title" href="' + result[i].linkUrl + '" target="_blank">' + result[i].title + '</a>'+
							'       <p>' + result[i].content + '</p>'+
							'	<a class="link-url" href="' + result[i].linkUrl + '" target="_blank">' + result[i].formatUrl + '</a>'+
							'</div>';
				}

				var pages = dataMap.pages;
				//上一页
				var prePage = dataMap.page > 1 ? dataMap.page-1 : 1;
				html +=
						'<div class="page-info">' +
						'	<ul class="page-ul">' +
						'		<li onclick="getPageData('+prePage+');">上一页</li>';

				for(var i=0; i<pages.length; i++) {
					var clz = dataMap.page==pages[i].label ? ' class="current" ' : '';
					html += '<li' + clz + ' onclick="getPageData(' + pages[i].label + ');">' + pages[i].label + '</li>';
				}

				var nextPage = dataMap.page>=pages[pages.length-1].label ? dataMap.page : dataMap.page + 1;
				html +=
						'		<li onclick="getPageData('+nextPage+');">下一页</li>' +
						'	</ul>' +
						'</div>';

				$("#resultList").html(html);
			} else {
				$("#resultList").html("<div class='search-tips'>"+data.msg+"</div>");
			}
		});
	}
</script>
<div id="script"></div>
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":["mshare","qzone","weixin","tsina","sqq","tqq","tieba","renren","douban","bdysc","bdxc","tqf","youdao","mail"],"bdPic":"","bdStyle":"0","bdSize":"16"},"slide":{"type":"slide","bdImg":"1","bdPos":"right","bdTop":"150"}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
</html>